package ocean.chinacraft.common.world.item;

import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import ocean.chinacraft.common.constants.Constants;

import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * 蚕
 *
 * @author zhang
 * @since 2021/12/18
 */
public class ModSilkWorm extends Item {

//    public static final int[] LIFE_CYCLE = new int[]{16000, 45000, 9000};
    public static final int[] LIFE_CYCLE = new int[]{10, 22, 33};

    public ModSilkWorm(Properties properties) {
        super(properties);
    }

    @Override
    public void appendHoverText(ItemStack itemStack, @Nullable World world, List<ITextComponent> textComponents,
                                ITooltipFlag tipFlag) {
        if (itemStack.getTag() != null) {
            textComponents.add(new TranslationTextComponent("tooltip.chinacraft.silk_worm.schedule").append(getDisplayNbt(itemStack)));
        }
    }

    public String getDisplayNbt(ItemStack stack) {
        CompoundNBT tag = stack.getTag();
        int schedule = tag.getInt(Constants.SILK_WORM_CYCLE);
        int levelSchedule = LIFE_CYCLE[tag.getInt(Constants.SILK_WORM_LEVEL)];
        return new BigDecimal(schedule).divide(new BigDecimal(levelSchedule), 2, RoundingMode.HALF_DOWN).multiply(
                new BigDecimal(100)).intValue() + "%";
    }
}
